import { Controller, Get, Inject, OnModuleInit, Param } from '@nestjs/common';
import {
  ClientGrpc,
} from '@nestjs/microservices';

interface FindById{
  id: number;
}

interface Book{
  id: number;
  name: string;
  desc: string;
}

interface BookService {
  findBook(param: FindById): Book;
  findOne(param: FindById):Book;
}

@Controller('hero')
export class HeroController implements OnModuleInit {
  @Inject('BOOK_PACKAGE')
  private client: ClientGrpc;

  private bookService: BookService;
  onModuleInit() {
    this.bookService = this.client.getService('BookService');
  }

  @Get('one')
  getOne() {
    return this.bookService.findOne({id:3})
  }

  @Get(':id')
  getHero(@Param('id') id: number) {
    return this.bookService.findBook({id})
  }

}